package kr.co.happenstance;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import org.json.JSONObject;

import kr.co.happenstance.lib.MatchingLib;
import kr.co.happenstance.lib.PaylogLib;
import kr.co.happenstance.lib.vo.BillingCheckResultVo;
import kr.co.happenstance.lib.vo.BuyCheckResultVo;
import kr.co.happenstance.lib.vo.InAppPurchaseData;
import kr.co.happenstance.lib.vo.LibResultVo;
import kr.co.happenstance.lib.vo.MatchingCountResultVo;
import kr.co.happenstance.lib.vo.MatchingRecipientAcceptCntResultVo;
import kr.co.happenstance.lib.vo.MatchingResultVo;
import kr.co.happenstance.util.AndroidUtil;

import com.android.vending.billing.IInAppBillingService;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.gson.Gson;

import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class MeetActivity extends BaseActivity implements View.OnClickListener{
	protected final String TAG = "<<<MeetActivity>>>";
	
	/**
	 * REQUEST_CODE - RecipientListActivity 호출
	 * 
	 */
	private final int REQUEST_CODE_RECIPIENT_LIST_ACTIVITY = 0;
	
	/**
	 * REQUEST_CODE - In App Billing 호출
	 */
	private final int REQUEST_CODE_IAB = 1001;
	
	
	/**
	 * 프로파일 전송 여부 - 현재 Activity를 호출한 Activity에서 넘어온 값으로 셋팅
	 */
	private String profileYN;
	
	/**
	 * 매칭 요청 시퀀스 (DB값)
	 */
	private int matchingRequestSeq;
	
	/**
	 * DeveloperPayload 시퀀스(DB값)
	 */
	private int developerPayloadSeq;
	
	private String developerPayload;
	
	/**
	 * 대기시간 종료 시간
	 */
	private Calendar waitingFinishDate;
	
	/**
	 * 수락 카운트
	 */
	private int recvCnt;
	
	/**
	 * 서버에 수락 카운트 조회중인지 체크 하는 변수
	 */
	private boolean isLoadingRecvCntTask;
	
	/**
	 * GoogleMap 객체
	 */
	private GoogleMap googleMap;
	
	/**
	 * 전송 카운트 TextView 객체 
	 */
	private TextView tvSendCnt;
	
	/**
	 * 수신 동의 카운트 TextView 객체
	 */
	private TextView tvRecvCnt;
	
	/**
	 * 약속시간 TextView 객체
	 */
	private TextView tvPromiseTime;
	
	/**
	 * 현재시간 TextView 객체
	 */
	private TextView tvCurrentTime;	
	
	/**
	 * 시간 변경을 위한 Handler 객체
	 */
	private Handler timerHadler;
	
	/**
	 * inApp 결제 금액(프로필 전송시 결제 금액)<br><br
	 *  
	 * Google Play의 In-App Billing 서비스를 통해 전달 받음 
	 */
	private String billingPrice;
	
	/**
	 * IInAppBillingService - InApp 결제 Serveice 객체<br><br>
	 * 
	 */
	private IInAppBillingService billingService;
	
	/**
	 * ServiceConnection 객체<br><br> 
	 * 
	 * Google Play의 In-App Billing 서비스와의 커넥션을 맺기 위해 ServiceConnection을 구현
	 * 
	 */
	private ServiceConnection serviceConn =  new ServiceConnection(){

		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			Log.d(TAG, "onServiceConnected.........");
			billingService = IInAppBillingService.Stub.asInterface(service);
			Log.d(TAG, "billingService["+billingService+"]");
		}

		@Override
		public void onServiceDisconnected(ComponentName name) {
			Log.d(TAG, "onServiceDisconnected.........");
			billingService = null;
		}
		
	};	
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_meet);
		init(this, C.MENU_ID_MEET);
		
		tvSendCnt = (TextView) this.findViewById(R.id.tv_send_cnt);
		tvSendCnt.setText("000명");
		
		tvRecvCnt = (TextView) this.findViewById(R.id.tv_recv_cnt);
		tvRecvCnt.setText("000명");
		tvRecvCnt.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View view, MotionEvent event) {
				switch(event.getAction()){
					case MotionEvent.ACTION_DOWN:
						tvRecvCnt.setTextColor(Color.BLACK);
						break;
					case MotionEvent.ACTION_UP:
						tvRecvCnt.setTextColor(Color.RED);
						break;
				}
				return false;
			}
		});
		
		tvPromiseTime = (TextView) this.findViewById(R.id.tv_promise_time);
		tvPromiseTime.setText("00:00");
		
		tvCurrentTime = (TextView) this.findViewById(R.id.tv_current_time);
		tvCurrentTime.setText(new SimpleDateFormat("a hh:mm", Locale.ENGLISH).format(new Date()));
		
		//프로필 전송 여부
		profileYN = getIntent().getStringExtra("profileYN");
		if(profileYN == null || profileYN.equals("")) profileYN="N";
		Log.d(TAG, "profileYN["+profileYN+"]");
		
		//맵셋팅
		settingMapAndAddress();
		
		//구현한 ServiceConnection 인스턴스를 가진 Intent를 파라미터로 하여 bindService 메소드를 호출
		this.bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND") , serviceConn, Context.BIND_AUTO_CREATE);
		Log.d(TAG, "bindService after.....");
		
		new MatchingCountTask().execute();
	}	
	
	@Override
	protected void onDestroy(){
		super.onDestroy();
		
		//타이머 종료
		if(timerHadler != null){
			timerHadler.removeMessages(0);
		}
		
		//In-App Billing 서비스를 종료
		if(billingService != null){
			this.unbindService(serviceConn);
			Log.d(TAG, "unbindService after....");
		}		
		
	}
	
	@Override
	protected void onResume(){
		super.onResume();
		if(timerHadler != null){
			timerHadler.sendEmptyMessage(0);
		}
	}
	
	@Override
	public void onClick(View view) {
		switch(view.getId()){
			case R.id.tv_recv_cnt:
				Intent intent = new Intent(this, RecipientListActivity.class);
				intent.putExtra("matchingRequestSeq", matchingRequestSeq);
				intent.putExtra("waitingFinishDateTimeInMillis", waitingFinishDate.getTimeInMillis());
				//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				//startActivity(intent);
				startActivityForResult(intent, REQUEST_CODE_RECIPIENT_LIST_ACTIVITY);
				break;
		}
	}
	
	@Override
	public void onBackPressed(){
		Toast.makeText(this, R.string.toast_msg_meet_wait, Toast.LENGTH_SHORT).show();
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		
		switch(requestCode){
			case REQUEST_CODE_RECIPIENT_LIST_ACTIVITY:
				if(resultCode == RESULT_OK){
					Log.d(TAG, "RecipientListActivity onActivityResult RESULT_OK...............");
					
					//RecipientListActivity에서 요청자가 선택한 수신자 아이디
					String recipientId = data.getStringExtra("recipientId");
					
					Intent intent = new Intent(this, WaitingRequestorActivity.class);
					intent.putExtra("matchingRequestSeq", matchingRequestSeq);
					intent.putExtra("recipientId", recipientId);
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
					startActivity(intent);
					finish();					
				}else{
					Log.d(TAG, "RecipientListActivity onActivityResult RESULT_CANCELED...............");
				}
				break;
			
			case REQUEST_CODE_IAB:
				if(resultCode == RESULT_OK){
					Log.d(TAG, "inAppBilling RESULT_OK..............");
					String inAppPurchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
					Log.d(TAG, "inAppPurchaseData["+inAppPurchaseData+"]");
					
					
					InAppPurchaseData billingResult = new Gson().fromJson(inAppPurchaseData, InAppPurchaseData.class);
					Log.d(TAG, "["+billingResult.getOrderId()+"]");
					Log.d(TAG, "["+billingResult.getPackageName()+"]");
					Log.d(TAG, "["+billingResult.getProductId()+"]");
					Log.d(TAG, "["+billingResult.getPurchaseTime()+"]");
					Log.d(TAG, "["+billingResult.getPurchaseState()+"]");
					Log.d(TAG, "["+billingResult.getDeveloperPayload()+"]");
					Log.d(TAG, "["+billingResult.getPurchaseToken()+"]");
					new MatchingTask().execute(billingResult);
					
				}else{
					Log.d(TAG, "inAppBilling RESULT_CANCELED..............");
					new CustomAlertDialogBuilder(MeetActivity.this)
					.setTitle(MeetActivity.this.getString(R.string.alert_title))
					.setMessage(getString(R.string.alert_msg_billing_cancel))
					.setCancelable(true)
					.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener(){
						@Override
						public void onClick(DialogInterface dialog, int arg1) {
							dialog.dismiss();
							MeetActivity.this.finish();
							
						}
					})
					.create();						
				}
				break;
				
		}

	}	
	
	
	/**
	 * Google Map 셋팅 메소드
	 * 
	 * <li>Map 좌표 현재 나의 위치로 이동</li>
	 * <li>Map 축척 변경</li>
	 * <li>Marker 표시</li>
	 * 
	 */
	private void settingMapAndAddress(){
		if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS && myLocation != null){
			
			LatLng position = new LatLng(myLocation.getLatitude(), myLocation.getLongitude());
			googleMap = ((SupportMapFragment) getSupportFragmentManager()	.findFragmentById(R.id.map)).getMap();
			
			//맵 위치이동.
			googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 15));
			
			MarkerOptions markerOptions = new MarkerOptions();
			markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker));
			markerOptions.position(position);
			
			//마커 설정.
			googleMap.addMarker(markerOptions).showInfoWindow();

		}
	}
	
	/**
	 * 매칭후 대기시간 초과시 팝업 다이얼로그 보여주는 메소드
	 */
	private void showMatchingFailDialog(){
		LayoutInflater inflater = (LayoutInflater) this.getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
		View layout = inflater.inflate(R.layout.popup_matching_fail, (ViewGroup) this.findViewById(R.id.rl_popup));
		
		//리스너 등록
		ImageButton btnClose = (ImageButton) layout.findViewById(R.id.btn_pop_close);
		ImageButton btnMeet2 = (ImageButton) layout.findViewById(R.id.btn_meet2);
		
		View.OnClickListener listener = new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				popupDialog.dismiss();
				Intent intent = new Intent(MeetActivity.this, HomeActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent);
				finish();
			}
		};
		
		btnClose.setOnClickListener(listener);
		btnMeet2.setOnClickListener(listener);
		
		popupDialog = AndroidUtil.getPopupDialog(this, layout, false);
		popupDialog.show();			
	}	
	
	/**
	 * 수락 완료 카운트 가져오는 Task 구동 메소드
	 */
	private void executeRecvCntTask(){
		new RecvCntTask().execute();
	}
	
	private void billingStart(){
		try {
			Log.d(TAG, "developerPayloadSeq["+developerPayloadSeq+"]");
			Log.d(TAG, "developerPayload["+developerPayload+"]");
			Bundle buyIntentBundle = billingService.getBuyIntent(C.IAB_API_VERSION, getPackageName(), C.IAB_ID, C.IAB_TYPE, developerPayload);
			Log.d(TAG, "buyIntentBundle["+buyIntentBundle+"]");
			
			PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
			Log.d(TAG, "pendingIntent["+pendingIntent+"]");
			
			startIntentSenderForResult(pendingIntent.getIntentSender(),REQUEST_CODE_IAB, new Intent(), Integer.valueOf(0), Integer.valueOf(0),Integer.valueOf(0));
			
		}catch(Exception e){
			e.printStackTrace();
			new CustomAlertDialogBuilder(MeetActivity.this)
			.setTitle(MeetActivity.this.getString(R.string.alert_title))
			.setMessage(getString(R.string.alert_msg_billing_info_fail))
			.setCancelable(false)
			.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener(){
				@Override
				public void onClick(DialogInterface dialog, int arg1) {
					dialog.dismiss();
					MeetActivity.this.finish();
				}
			})
			.create();				
			
		}
	}
	
	/**
	 * 매칭 건수 가져오는 Task 클래스
	 * @author Administrator
	 */
	private class MatchingCountTask extends AsyncTask<Void, Void, LibResultVo> {
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgress();
		}	
		
		@Override
		protected LibResultVo doInBackground(Void... arg0) {
			LibResultVo vo = null;
			try{
				
				MatchingLib lib = new MatchingLib();
				vo = lib.matchingCount(myApp.id, Double.toString(myLocation.getLatitude()), Double.toString(myLocation.getLongitude()));
				
			}catch(Exception e){
				e.printStackTrace();
			}
			return vo;			
		}
		
		@Override
		protected void onPostExecute(LibResultVo resultVo) {
			closeProgress();
			MatchingCountResultVo vo = (MatchingCountResultVo)resultVo;
			if(vo == null || vo.getResult().equals(C.API_RESULT_VALUE_FAIL)){
				Log.d(TAG, "MatchingCountResultVo null......");
				new CustomAlertDialogBuilder(MeetActivity.this, R.string.alert_title, R.string.alert_msg_exception).create();
				
			}else{
				Log.d(TAG, "matchCnt["+vo.getMatchingCnt()+"]");
				if(vo.getMatchingCnt() > 0){
					if(profileYN.equals("Y")){
						new BillingCheckTask().execute();
					}else{
						new MatchingTask().execute();
					}
					
				}else{
					//매칭실패 팝업
					showMatchingFailDialog();
				}
				
			}	
		}	
		
	}
	
	/**
	 * 빌링 체크 테스크 클래스
	 * 
	 * @author Administrator
	 *
	 */
	private class BillingCheckTask extends AsyncTask<Void, Void, LibResultVo>{
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgress();
		}
		
		@Override
		protected LibResultVo doInBackground(Void... params) {
			LibResultVo vo = null;
			try{
				
				MatchingLib lib = new MatchingLib();
				vo = lib.billingCheck(myApp.id);
				
			}catch(Exception e){
				e.printStackTrace();
			}
			return vo;	
		}
		
		@Override
		protected void onPostExecute(LibResultVo resultVo) {
			closeProgress();
			BillingCheckResultVo vo = (BillingCheckResultVo)resultVo;
			if(vo == null || vo.getResult().equals(C.API_RESULT_VALUE_FAIL)){
				Log.d(TAG, "BillingCheckResultVo null......");
				new CustomAlertDialogBuilder(MeetActivity.this)
				.setTitle(MeetActivity.this.getString(R.string.alert_title))
				.setMessage(getString(R.string.alert_msg_exception))
				.setCancelable(false)
				.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int arg1) {
						dialog.dismiss();
						MeetActivity.this.finish();
						
					}
				})
				.create();						
			}else{
				Log.d(TAG, "isBilling["+vo.isBilling()+"]");
				if(vo.isBilling()){
					developerPayload = vo.getDeveloperPayload();
					developerPayloadSeq = vo.getSeq();
					
					new InAppBillGetPriceTask().execute();
				}else{
					Log.d(TAG, "no billing......");
					new MatchingTask().execute();
				}
			}
		}	
		
	}
	
	
	/**
	 * 매칭 요청 Task 클래스
	 * 
	 * @author Administrator
	 *
	 */
	private class MatchingTask extends AsyncTask<InAppPurchaseData, Void, LibResultVo> {
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgress();
		}	
		
		@Override
		protected LibResultVo doInBackground(InAppPurchaseData... params) {
			LibResultVo vo = null;
			
			try{
				MatchingLib lib = new MatchingLib();
				
				Log.d(TAG, "params["+params.length+"]");
				if(params != null && params.length>0 && params[0] != null){
					
					//정상 구매 체크
					BuyCheckResultVo vo2 =  (BuyCheckResultVo) lib.buyCheck(params[0].getDeveloperPayload(), developerPayloadSeq, params[0].getOrderId());
					if(vo2 == null || vo2.getResult().equals(C.API_RESULT_VALUE_FAIL) || !vo2.isValidate()){
						throw new Exception("비정상 구매");
					}
					
					//구매 상품 소진 요청(이거 안하면 재구매 안됨)
					int response = billingService.consumePurchase(C.IAB_API_VERSION, getPackageName(), params[0].getPurchaseToken());
					Log.d(TAG, "구매상품 소진 요청 결과["+response+"]");
					
					
					//결제 저장
					new PaylogLib().insert(myApp.id, Integer.parseInt(billingPrice), params[0].getOrderId(), response);
				}
				
				
				vo = lib.matching(myApp.id, Double.toString(myLocation.getLatitude()), Double.toString(myLocation.getLongitude()), profileYN);
			}catch(Exception e){
				e.printStackTrace();
			}
			return vo;	
		}
		
		@Override
		protected void onPostExecute(LibResultVo resultVo) {
			closeProgress();
			MatchingResultVo vo = (MatchingResultVo)resultVo;
			if(vo == null || vo.getResult().equals(C.API_RESULT_VALUE_FAIL)){
				Log.d(TAG, "MatchingResultVo null......");
				new CustomAlertDialogBuilder(MeetActivity.this)
				.setTitle(MeetActivity.this.getString(R.string.alert_title))
				.setMessage(getString(R.string.alert_msg_exception))
				.setCancelable(false)
				.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int arg1) {
						dialog.dismiss();
						MeetActivity.this.finish();
					}
				})
				.create();		
				
			}else{
				Log.d(TAG, "sendCnt["+vo.getSendCnt()+"]");
				if(vo.getSendCnt()>0){
					//요기서 프로파일 전송 유무에 따라 과금 진행
					
					//전송완료 셋팅 
					tvSendCnt.setText(String.format("%03d명", vo.getSendCnt()));
					matchingRequestSeq = vo.getMatchingRequestSeq();
					
					//대기시간 셋팅(현재 시간의 대기시간 더한거)
					waitingFinishDate = Calendar.getInstance();
					waitingFinishDate.add(Calendar.MINUTE, vo.getWaitMinute());
					
					//타이머 돌리기 시작
					timerHadler = new TimerHandler(MeetActivity.this);
					timerHadler.sendEmptyMessage(0);
				}
			}
		}
	}
	
	/**
	 * 수락 완료 카운트 가져오는 Task 클래스
	 * 
	 * @author Administrator
	 *
	 */
	private class RecvCntTask extends AsyncTask<Void, Void, LibResultVo> {
		@Override
		protected void onPreExecute() {
			isLoadingRecvCntTask = true;
		}
		
		@Override
		protected LibResultVo doInBackground(Void... params) {
			LibResultVo vo = null;
			try{
				MatchingLib lib = new MatchingLib();
				vo = lib.matchingRecipientAcceptCount(matchingRequestSeq);
			}catch(Exception e){
				e.printStackTrace();
			}
			return vo;	
		}
		
		@Override
		protected void onPostExecute(LibResultVo resultVo) {
			MatchingRecipientAcceptCntResultVo vo = (MatchingRecipientAcceptCntResultVo) resultVo;
			if(vo != null && vo.getResult().equals(C.API_RESULT_VALUE_SUCCESS)){
				recvCnt = vo.getMatchingRecipientAcceptCnt();
				tvRecvCnt.setText(String.format("%03d명", recvCnt));
			}
			isLoadingRecvCntTask = false;
		}
		
	}	
	
	/**
	 * 현재시간과 대기시간 출력 Handler 클래스
	 * 
	 * @author Administrator
	 *
	 */
	private static class TimerHandler extends Handler{
		SimpleDateFormat formatter = new SimpleDateFormat("a hh:mm", Locale.ENGLISH);
		MeetActivity activity;
		boolean finish = false;
		long diffSec;
		int min, sec;
		
		public TimerHandler(MeetActivity activity){
			this.activity = activity;
		}
		
		public void handleMessage(Message msg){
			
			if(activity.waitingFinishDate.getTimeInMillis() - Calendar.getInstance().getTimeInMillis() < 0  && !finish){
				//대기시간 초과시
				finish = true;
				this.removeMessages(0);
				activity.showMatchingFailDialog();				
			}else{
				
				diffSec = (activity.waitingFinishDate.getTimeInMillis() - Calendar.getInstance().getTimeInMillis()) / 1000; 
				min = (int) (diffSec / 60);
				sec = (int) (diffSec % 60);			
				
				activity.tvPromiseTime.setText(String.format("%02d:%02d", min, sec));
				activity.tvCurrentTime.setText(formatter.format(new Date()));				
				
				//5초마다 수락 카우트 조회
				if(!activity.isLoadingRecvCntTask && diffSec%5 == 0){
					activity.executeRecvCntTask();
				} 				
				this.sendEmptyMessageDelayed(0,1000);
				
			}
				
		}		
	}
	
	/**
	 * InApp 가격 정보 가져오는 Task 클래스
	 * 
	 * @author Administrator
	 *
	 */
	private class InAppBillGetPriceTask extends AsyncTask<Void, Void, Bundle>{
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			showProgress();
		}			
		
		@Override
		protected Bundle doInBackground(Void... params) {
			Bundle skuDetails = null;
			
			try{
				//billingService 를 가져올때 까지 돌린다~~~돌려돌려~~~
				int loopCnt = 0;
				while(billingService == null){
					Thread.sleep(300L);
					if(loopCnt > 10){
						throw new Exception("billingService Binding Fail.................");
					}
				}
				
				ArrayList<String> skuList = new ArrayList<String>();
				skuList.add(C.IAB_ID);
				
				Bundle querySkus = new Bundle();
				querySkus.putStringArrayList(C.IAB_BUNDLE_KEY_BILLING_INFO, skuList);
				
				skuDetails = billingService.getSkuDetails(C.IAB_API_VERSION, MeetActivity.this.getPackageName()	, C.IAB_TYPE, querySkus);
				
			}catch(Exception e){
				e.printStackTrace();
			}
			
			return skuDetails;
		}
		
		@Override
		protected void onPostExecute(Bundle result) {
			closeProgress();
			Log.d(TAG, "result["+result.describeContents()+"]");
			if(result != null){
				try{
					int response = result.getInt("RESPONSE_CODE");
					Log.d(TAG, "InAppBillGetPriceTask response["+response+"]");
					if(response == 0){
						ArrayList<String> responseList = result.getStringArrayList("DETAILS_LIST");

						Log.d(TAG, "InAppBillGetPriceTask responseList["+responseList.size()+"]");
						
						for(String thisResponse : responseList){
							JSONObject jsonObj = new JSONObject(thisResponse);
							String productId = jsonObj.getString("productId");
							String price = jsonObj.getString("price");
							
							Log.d(TAG, "productId["+productId+"], price["+price+"]");
							if(productId.equals(C.IAB_ID)){
								billingPrice = price;
							}
						}
					}
					
				}catch(Exception e){
					e.printStackTrace();
				}

			}//if(result != null)
			Log.d(TAG, "billingPrice["+billingPrice+"]");
			if(billingPrice == null || billingPrice.equals("")){
				new CustomAlertDialogBuilder(MeetActivity.this)
				.setTitle(MeetActivity.this.getString(R.string.alert_title))
				.setMessage(getString(R.string.alert_msg_billing_info_fail))
				.setCancelable(false)
				.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener(){
					@Override
					public void onClick(DialogInterface dialog, int arg1) {
						dialog.dismiss();
						MeetActivity.this.finish();
					}
				})
				.create();					
				
			}else{
				billingPrice = billingPrice.substring(1);
				Log.d(TAG, "billingPrice["+billingPrice+"]");		
				
				
				billingStart();
			}
			
			
		}	
		
	}//class InAppBillGetPriceTask	
	

	
}
